// Copyright 2022 marcello<volibearw@gmail.com>. All rights reserved.

package main

const ImportGormPath = "gorm.io/gorm"

// DataType 数据类型
type DataType string

const (
	/* Go 数据类型 */

	MySQLTypeUnknown   DataType = "UNKNOWN"
	MySQLTypeTinyint            = "TINYINT"
	MySQLTypeSmallint           = "SMALLINT"
	MySQLTypeMediumint          = "MEDIUMINT"
	MySQLTypeInt                = "INT"
	MySQLTypeInteger            = "INTEGER" // alias INT
	MySQLTypeBigint             = "BIGINT"
	MySQLTypeFloat              = "FLOAT"
	MySQLTypeDouble             = "DOUBLE"
	MySQLTypeDecimal            = "DECIMAL"

	MySQLTypeDate      = "DATE"
	MySQLTypeYear      = "YEAR"
	MySQLTypeDatetime  = "DATETIME"
	MySQLTypeTimestamp = "TIMESTAMP"

	MySQLTypeTinyblob   = "TINYBLOB"
	MySQLTypeBlob       = "BLOB"
	MySQLTypeMediumblob = "MEDIUMBLOB"
	MySQLTypeLongblob   = "LONGBLOB"
	/*
		MySQLTypeTime       = "TIME"
		MySQLTypeChar       = "CHAR"
		MySQLTypeVarchar    = "VARCHAR"
		MySQLTypeTinytext   = "TINYTEXT"
		MySQLTypeText       = "TEXT"
		MySQLTypeMediumtext = "MEDIUMTEXT"
		MySQLTypeLongtext   = "LONGTEXT"
	*/
	/* Go 数据类型 */

	GoTypeInt32    = "int32"
	GoTypeInt64    = "int64"
	GoTypeUint32   = "uint32"
	GoTypeUint64   = "uint64"
	GoTypeFloat32  = "float32"
	GoTypeFloat64  = "float64"
	GoTypeString   = "string"
	GoTypeByteArr  = "[]byte"
	GoTypeDateTime = "time.Time" // 特殊

	/* protobuf3 数据类型 */

	Protobuf3Float  = "float"  // float32
	Protobuf3Int32  = "int32"  // int32
	Protobuf3Int64  = "int64"  // int64
	Protobuf3Uint32 = "uint32" // uint32
	Protobuf3Uint64 = "uint64" // uint64
	/*
		Protobuf3Double = "double" // float64
		Protobuf3Sint32   = "sint32"   // int32
		Protobuf3Sint64   = "sint64"   // int64
		Protobuf3Fixed32  = "fixed32"  // uint32
		Protobuf3Fixed64  = "fixed64"  // uint64
		Protobuf3Sfixed32 = "sfixed32" // int32
		Protobuf3Sfixed64 = "sfixed64" // int64
	*/

	Protobuf3String = "string" // string
	Protobuf3Bytes  = "bytes"  // []byte

)

// Columns 生成结果需要的列
// 从 information_schema.columns 表中查出
type Columns struct {
	TableSchema string `gorm:"column:TABLE_SCHEMA"`
	TableName   string `gorm:"column:TABLE_NAME"`
	ColumnName  string `gorm:"column:COLUMN_NAME"`
	ColumnType  string `gorm:"column:COLUMN_TYPE"`
	DataType    string `gorm:"column:DATA_TYPE"`
	IsNullable  string `gorm:"column:IS_NULLABLE"`
	Comment     string `gorm:"column:COLUMN_COMMENT"`

	// 以下额外数据不是字段
	TableNameFirstWordLowercase     string `gorm:"-"` // 表名首字母,小写
	TableNameCame                   string `gorm:"-"` // 表名驼峰
	TableNameCameFirstWordLowercase string `gorm:"-"` // 表名驼峰,首字母小写

	ColumnNameCame      string `gorm:"-"` // 字段名驼峰
	ColumnNameSnake     string `gorm:"-"` // 字段蛇形命名
	ColumnProtoDataType string `gorm:"-"` // 对应的proto字段类型
	ColumnGoDataType    string `gorm:"-"` // 对应的Go数据类型
}

// CLIParam 命令行参数
type CLIParam struct {
	// 数据库参数
	Host    string
	Port    uint
	User    string
	Passwd  string
	Schema  string
	Charset string

	// 输出model参数
	Model                    bool   // 输出开关
	ModelOut                 string // 输出目录
	ModelIncludeProtoConvert bool   // 是否输出与proto转换函数
	ModelUseGorm             bool   // 生成的model结构体中是否包含gorm tag
	ModelIncludeGormModel    bool   // 生成的Model中是否组合 gorm.Model 结构
	ModelImportPbPath        string // 生成Model文件中pb文件的导入路径
	ModelFilePackage         string // 生成Model文件 package name
	ModelOverwrite           bool   // 当model文件存在时,自动覆盖旧文件

	// 输出Proto参数
	Proto                bool   // pb 输出开关
	ProtoOut             string // pb 输出目录
	ProtoPackage         string // protobuf 文件 PackageName
	ProtoOptionGoPackage string // option go_package
}
